
package com.tools.cleanmaster.utils;

import android.content.Context;
import android.text.TextUtils;

import com.tools.cleanmaster.R;
import com.tools.cleanmaster.model.item.FileTrashItem;

import java.io.File;

import static com.tools.cleanmaster.utils.MimeTypes.MIME_FLAC;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_EXCEL;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_EXCEL_XLSX;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_EXCEL_XLTX;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_POWERPOINT;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_POWERPOINT_POTX;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_POWERPOINT_PPSX;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_POWERPOINT_PPTX;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_WORD;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_WORD_DOCX;
import static com.tools.cleanmaster.utils.MimeTypes.MIME_MS_WORD_DOTX;

public final class TrashMimeTypes {
    private TrashMimeTypes() {
    }

    public static String getMimeType(String fileName) {
        return MimeTypes.getInstance().getMimeType(fileName);
    }

    @SuppressWarnings("static-access")
    public static String getFileFormatText(Context context, String filePath) {
        if (TextUtils.isEmpty(filePath)) {
            return context.getString(R.string.trash_clean_file_type_other);
        }

        String fileName = new File(filePath).getName();
        int fileType = getFileTypes(fileName);
        switch (fileType) {
            case FileTrashItem.FILE_TYPE_PHOTO:
                return context.getString(R.string.trash_clean_file_type_image);
            case FileTrashItem.FILE_TYPE_VIDEO:
                return context.getString(R.string.trash_clean_file_type_video);
            case FileTrashItem.FILE_TYPE_APK:
                return context.getString(R.string.trash_clean_file_type_app);
            case FileTrashItem.FILE_TYPE_MUSIC:
                return context.getString(R.string.trash_clean_file_type_audio);
            case FileTrashItem.FILE_TYPE_DOC:
                return context.getString(R.string.trash_clean_file_type_doc);
            case FileTrashItem.FILE_TYPE_DEFAULT:
            default: {
                return context.getString(R.string.trash_clean_file_type_other);
            }
        }
    }
//
//    @SuppressWarnings("static-access")
//    public static int getIconResourceIdByType(File file) {
//        if (file.isDirectory()) {
//            return R.drawable.transhcleaning_directorytrash;
//        }
//        int fileType = getFileTypes(file.getName());
//        switch (fileType) {
//            case FileTrashItem.FILE_TYPE_APK:
//                return R.drawable.transhcleaning_apktrash;
//            case FileTrashItem.FILE_TYPE_MUSIC:
//                return R.drawable.transhcleaning_musictrash;
//            case FileTrashItem.FILE_TYPE_DOC:
//                return R.drawable.transhcleaning_documenttrash;
//            case FileTrashItem.FILE_TYPE_PHOTO:
//                return R.drawable.transhcleaning_pictrash;
//            case FileTrashItem.FILE_TYPE_VIDEO:
//                return R.drawable.transhcleaning_videotrash;
//            case FileTrashItem.FILE_TYPE_DEFAULT:
//            default:
//                return R.drawable.transhcleaning_othertrash;
//        }
//    }

    public static int getFileTypes(String fileName) {
        String mimeType = getMimeType(fileName);
        if (TextUtils.isEmpty(mimeType)) {
            return FileTrashItem.FILE_TYPE_DEFAULT;
        }

        if (mimeType.startsWith("application")) {
            if (MimeTypes.MIME_APK.equals(mimeType)) {
                return FileTrashItem.FILE_TYPE_APK;
            } else if (MIME_MS_WORD.equals(mimeType)
                    || MIME_MS_WORD_DOCX.equals(mimeType)
                    || MIME_MS_WORD_DOTX.equals(mimeType)
                    || MIME_MS_EXCEL.equals(mimeType)
                    || MIME_MS_EXCEL_XLSX.equals(mimeType)
                    || MIME_MS_EXCEL_XLTX.equals(mimeType)
                    || MIME_MS_POWERPOINT.equals(mimeType)
                    || MIME_MS_POWERPOINT_PPTX.equals(mimeType)
                    || MIME_MS_POWERPOINT_POTX.equals(mimeType)
                    || MIME_MS_POWERPOINT_PPSX.equals(mimeType)) {
                return FileTrashItem.FILE_TYPE_DOC;
            } else if (MIME_FLAC.equals(mimeType)) {
                // Flac
                return FileTrashItem.FILE_TYPE_MUSIC;
            }
            return FileTrashItem.FILE_TYPE_DEFAULT;
        } else if (mimeType.startsWith("ani/images")) {
            return FileTrashItem.FILE_TYPE_PHOTO;
        } else if (mimeType.startsWith("video")) {
            return FileTrashItem.FILE_TYPE_VIDEO;
        } else if (mimeType.startsWith("audio")) {
            return FileTrashItem.FILE_TYPE_MUSIC;
        } else if (mimeType.startsWith("text")) {
            return FileTrashItem.FILE_TYPE_DOC;
        } else {
            return FileTrashItem.FILE_TYPE_DEFAULT;
        }
    }
}
